<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		function objectCopy(obj) {
			function Fun() { };
			Fun.prototype = obj;
			return new Fun();
		}

		function createAnother(original,name,friends) {
			let clone = objectCopy(original);
			clone.name = '小明';
			clone.friends = ["郭敬明", "韩寒"]
			clone.getName = function () {
				console.log(this.name);
			};
			return clone;
		}

		let person = {
			name: "yhd",
			friends: ["rose", "tom", "jack"]
		}

		let person1 = createAnother(person);
		person1.friends.push("lily");
		console.log(person1.friends);
		person1.getName(); // yhd

		let person2 = createAnother(person);
		console.log(person2.friends); // ["rose", "tom", "jack", "lily"]
	</script>
</body>

</html>